<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/15
 * Time: 15:21
 */

namespace Home\Controller;
use Think\Controller;
use Think\Model;

class ActivityController extends BaseController {

    public function get_activity_list()
    {
       $model = M('activity');
        $data = $model->where(1)->order(array('action_time'=>'desc'))->select();
        foreach($data as $key=>$value)
        {
            $date = $data[$key]['action_time'];
            $today = date("Y-m-d",strtotime("-1 day"));
            if($date>$today)
            {
               $data[$key]['statu'] = 1;//活动没有过期
            }else{
               $data[$key]['statu'] = 2;//活动过期了
            }
        }
      echo json_encode($data);
    }

    public function qiniu()
    {
        $model = D('activity');
        $setting=C('UPLOAD_SITEIMG_QINIU');
        $Upload = new \Think\Upload($setting);
//        var_dump($_FILES);
        $info = $Upload->upload($_FILES);
//        var_dump($info);
        $url = $info['pic']['url'];
        $image = $this->imageinfo($url);
        $data = array(
            'cover'=>$url,
            'width'=>$image['width'],
            'height'=>$image['height'],
            'up_time'=>date('Y-m-d H:i:s',time()),
        );
        $model->data($data)->add();
    }

    //点击进去的H5页面
    public function show_html()
    {
        $this->display();
    }
}